home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / misc / sss.lha / sss / cod / opts.ei < prev    next >
Text File  |  1994-06-20  |  7KB  |  249 lines

  1. *******************************************************************************
  2. * ParseCmdLn 1.2.3
  3. *******************************************************************************
  4. * INFO    executes the parsing of a commandline and sets the variables
  5. *    accordingly
  6. * SYN    success = ParseCmdLn[StrPtr]
  7. *    d0.l                 a0.l
  8. * IN    StrPtr    pointer to commandline string
  9. * OUT    success    0=ERROR! else OK
  10. * MOD    FlNm    filled with the input filename
  11. *    BsNm    filled with the base name (if specified)
  12. *    flgs    bit # F_QUIETMODE updated
  13. *******************************************************************************
  14.  
  15.     function ParseCmdLn[a0],a0:d0
  16.  
  17.     moveq.l    #0,d0    ;returncode
  18.  
  19.     SkpSpcs[a0]
  20.     when.s #"-q"=(a0).w    ;if quiet mode
  21.      bset.b    #F_QUIETMODE,flgs    ;set appropriate flag
  22.      addq.l    #2,a0    ;skip "-q"
  23.      SkpSpcs[a0]
  24.     ewhen
  25.  
  26.     when.s GetFlNm[sav:a0,#InFl]    ;if InFl specified (correctly)
  27.      SkpSpcs[a0]
  28.  
  29.      move.l    ValU[a0],ChnkSz    ;get chunk length
  30.      when.s d0 & {#$7fffffff»=d0}    ;d0 returned by ValU[]
  31.       SkpSpcs[a0]
  32.       when.s ~GetFlNm[a0,#OutBs]    ;if OutBs not specified (correctly)
  33.        clr.b    OutBs    ;void its path
  34.       ewhen
  35.       moveq.l    #-1,d0    ;commamdline is good
  36.      othw
  37.       moveq.l    #0,d0    ;error
  38.      ewhen
  39.  
  40.     ewhen
  41.  
  42.     efunc
  43.  
  44.  
  45.  
  46. *******************************************************************************
  47. * GetFlNm 1.2.2
  48. *******************************************************************************
  49. * INFO    copies a filename, discarding the ""s or ''s (if present);
  50. *    it stops at the first ENTER,BLANK or SPACE and NULL-terminates
  51. *    the string copied
  52. * SYN    NewStrPtr = GetFlNm[StrPtr,DstBufAdr]
  53. *    a0.l                a1.l   a2.l
  54. * IN    StrPtr    pointer to string (filename)
  55. *    DstBufAdr    address of destination buffer
  56. * OUT    NewStrPtr    pointer after source filename (0 if ERROR!)
  57. * WARN    be careful there is *no* check!!!
  58. *******************************************************************************
  59.  
  60.     function    GetFlNm[a1-a2],d0/a1-a2:a0
  61.  
  62.     move.b    (a1),d0    ;get first character
  63.  
  64.     when.s {#"'"=d0.b}|{#'"'=d0.b}    ;if quoted...
  65.      CpyQtd.s[a1,a2]    ;returns in a0.l
  66.  
  67.     owhen {#0=d0.b}|{#10=d0.b}|{#' '=d0.b} ;else if BLANK or ENTER...
  68.      suba.l    a0,a0    ;error!
  69.  
  70.     othw
  71.      addq.l    #1,a1    ;skip character already picked
  72.      repeat
  73.       move.b    d0,(a2)+    ;store character
  74.       move.b    (a1)+,d0    ;get new character
  75.      until.s {#0=d0.b}|{#10=d0.b}|{#' '=d0.b}
  76.      clr.b    (a2)    ;NULL-terminated
  77.      movea.l    a1,a0    ;update source pointer
  78.     ewhen
  79.  
  80.     pop
  81.  
  82.  
  83.  
  84. *******************************************************************************
  85. * CpyQtd 1.1.2
  86. *******************************************************************************
  87. * INFO    copies a string enclosed between two quotes: it is considered
  88. *    a "quote" the first char of the string;
  89. *    the copy is NULL-terminated;
  90. *    it fails at the first ENTER or BLANK
  91. * SYN    CpyQtd[StrPtr,DstBufAdr]
  92. *           a1.l   a2.l
  93. * IN    StrPtr    pointer to string (filename)
  94. *    DstBufAdr    address of destination buffer
  95. * MOD    a0.l    pointer after string (0 if ERROR!)
  96. * WARN    be careful there is *no* check!!!
  97. * NOTE    local procedure of GetFlNm[]
  98. *******************************************************************************
  99. *
  100.     procedure loc:CpyQtd[a1-a2],d0-d1/a1-a2
  101.     move.b    (a1)+,d0    ;get "quote"
  102.     repeat
  103.      move.b    (a1)+,d1
  104.  
  105.      switch.s d1.b
  106.      -> d0        ;successful copy
  107.       clr.b    (a2)    ;NULL-termination
  108.       moveq.l    #0,d1    ;exit loop
  109.      -> #0        ;unvalid character, exit loop
  110.       suba.l    a1,a1    ;error
  111.      -> #10        ;unvalid character
  112.       moveq.l    #0,d1    ;exit loop
  113.       suba.l    a1,a1    ;error
  114.      def
  115.       move.b    d1,(a2)+    ;copy character
  116.      eswitch
  117.  
  118.     until.s ~d1.b
  119.     movea.l    a1,a0    ;new string pointer
  120.  
  121.     eproc
  122. *
  123. *******************************************************************************
  124.  
  125.     efunc
  126.  
  127.  
  128.  
  129. *******************************************************************************
  130. * settings 1.1.5
  131. *******************************************************************************
  132. * INFO    reserves the memory and opens the files according to the
  133. *    values retrived by ParseCmdLn[]
  134. * SYN    ErrCode = settings[]
  135. *    d0.l
  136. * OUT    ErrCode    0=OK, else E_xxxxxx (see defs.i)
  137. * REQ    _DOSName    address of "dos.library",0
  138. *******************************************************************************
  139.  
  140.     function    settings[],d1/a0-a1/a6:d0
  141.  
  142.     move.l    ChnkSz,d0
  143.     moveq.l    #0,d1    ;best available memory
  144.     movea.l    4.w,a6
  145.     jsr    (_LVOAllocMem,a6)
  146.  
  147.     when d0.l        ;if enough memory for a whole
  148.      move.l    ChnkSz,WrkBufLen    ;chunk, BufSz=ChnkSz
  149.     othw        ;else allocate biggest buffer available
  150.      move.l    #MEMF_LARGEST,d1
  151.      jsr    (_LVOAvailMem,a6)
  152.      move.l    d0,WrkBufLen    ;size of biggest buffer
  153.      moveq.l    #0,d1    ;best available memory
  154.      jsr    (_LVOAllocMem,a6)
  155.     ewhen
  156.  
  157.     when d0.l        ;if buffer successfully reserved
  158.      move.l    d0,WrkBufAdr    ;keep buffer address
  159.      move.l    #InFl,d1
  160.      move.l    #MODE_OLDFILE,d2
  161.      movea.l    _DOSBase,a6
  162.      jsr    (_LVOOpen,a6)
  163.  
  164.      when d0.l
  165.       move.l    d0,InFlHnd    ;store handle
  166.  
  167.       lea.l    OutBs,a0
  168.       when.s    ~(a0).b    ;if no OutBs specified
  169.        lea.l    InFl,a1    ;copy source filename
  170.        repeat
  171.         move.b    (a1)+,d0
  172.         move.b    d0,(a0)+
  173.        until ~d0.b
  174.  
  175.       othw
  176.        while (a0)+.b    ;find end of OutBs
  177.        ewhile
  178.       ewhen
  179.  
  180.       move.b    #'.',(-1,a0)    ;extension dot
  181.       move.l    a0,ExtnAdr    ;store pointer to final BLANK
  182.  
  183.       move.l    GetFlSz[InFlHnd],InFlSz
  184.       divul.l    ChnkSz,d1:d0    ;d0=max chunk number
  185.       when.s ~d1.l
  186.        subq.l    #1,d0    ;maximum chunk number
  187.       ewhen
  188.       when.s #MAXCHNKSNO»d0    ;if reasonable number of chunks
  189.        move.l    d0,MaxChnk
  190.        moveq.l    #1,d1    ;minimum number of digits
  191.        while.s #10«=d0.l
  192.         addq.l    #1,d1    ;one more digit needed
  193.         divu.l    #10,d0
  194.        ewhile
  195.        move.l    d1,DgtNo
  196.        moveq.l    #0,d0    ;no error
  197.       othw
  198.        moveq.l    #E_CHNKNO,d0    ;too many chunks
  199.       ewhen
  200.  
  201.      othw
  202.       moveq.l    #E_SOUFL,d0
  203.      ewhen
  204.  
  205.     othw
  206.      moveq.l    #E_LOWMEM,d0    ;not enough memory
  207.     ewhen
  208.  
  209.     efunc
  210.  
  211.  
  212.  
  213. *******************************************************************************
  214. * GvInfo 1.1.1
  215. *******************************************************************************
  216. * INFO    prints some info about the current operations
  217. * SYN    GvInfo[]
  218. * NOTE    - prt[] and StrU[] always called without "sav:"
  219. *      (regs already saved)
  220. *    - uses TmpBuf
  221. *******************************************************************************
  222.  
  223.     procedure GvInfo[],d0-d2/a0
  224.     prt[#txt_InfoFlNm]
  225.     prt[#InFl]
  226.     prt[#txt_ENTER]    ;show source name
  227.  
  228.     prt[#txt_InfoOFl]
  229.     StrU[#0,ExtnAdr,DgtNo]    ;build first extension
  230.     prt[#OutBs]        ;show first chunk filename
  231.  
  232.     when.s MaxChnk.l    ;if 2+ chunks
  233.      prt[#txt_InfoArw]
  234.      StrU[MaxChnk,ExtnAdr,DgtNo]    ;build last extension
  235.      prt[#OutBs]    ;show last chunk filename
  236.     ewhen
  237.     prt[#txt_ENTER]
  238.  
  239.     prt[#txt_InfoCSz]
  240.     StrU[ChnkSz,#TmpBuf,#10]
  241.     prt[#TmpBuf]    ;show chunk size
  242.     prt[#txt_InfoBytes]
  243.  
  244.     prt[#txt_InfoBSz]
  245.     StrU[WrkBufLen,#TmpBuf,#10]
  246.     prt[#TmpBuf]    ;show buffer size
  247.     prt[#txt_InfoBytes]
  248.     eproc
  249.